package com.example.listfragment;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SimpleListFragment extends ListFragment {

	String[] menu = new String[] {"Information", "Map", "QR", "Contact", "Homepage"	};
	Fragment fr;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(),android.R.layout.simple_list_item_1, menu);
		setListAdapter(adapter);
		return super.onCreateView(inflater, container, savedInstanceState);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		String clickedDetail = (String)l.getItemAtPosition(position);
		//Fragment fr;
		//FragmentManager fragmentManager = getFragmentManager();
		//FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		if (clickedDetail.contentEquals("Information")) {
//			FragmentManager fm = getFragmentManager();
//			FragmentTransaction ft = fm.beginTransaction();
//			Fragment newFragment = new ExampleFragment();
//			FragmentTransaction transaction = getFragmentManager().beginTransaction();
//			transaction.replace(R.id.list, newFragment);
//			transaction.addToBackStack(null);
//			transaction.commit();
			fr = new ExampleFragment();
		}else if (clickedDetail.contentEquals("Map")) {
			fr = new ExampleFragment();
		}
		
		FragmentManager fm = getFragmentManager();
		FragmentTransaction ft = fm.beginTransaction().replace(R.id.example, fr);
		
		ft.commit();
		
		
	}
}
